package com.example.dllo.exe.fenlei.danpin;

import android.content.Intent;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import android.view.View;

import android.widget.ImageView;
import android.widget.TextView;

import com.example.dllo.exe.R;
import com.example.dllo.exe.bean.DanPinPinJieBean;

import com.example.dllo.exe.fengzhuang.NetTool;

import com.example.dllo.exe.main.BaseAty;


/**
 * code is far away from bug with the animal protecting
 * <p>
 * ┏┓　　　┏┓
 * ┏┛┻━━━┛┻┓
 * ┃　　　　　　　┃
 * ┃　　　━　　　┃
 * ┃　┳┛　┗┳　┃
 * ┃　　　　　　　┃
 * ┃　　　┻　　　┃
 * ┃　　　　　　　┃
 * ┗━┓　　　┏━┛
 * 　　┃　　　┃神兽保佑
 * 　　┃　　　┃永无BUG！  凯哥 祝你一路顺风
 * 　　┃　　　┗━━━┓
 * 　　┃　　　　　　　┣┓
 * 　　┃　　　　　　　┏┛
 * 　　┗┓┓┏━┳┓┏┛
 * 　　　┃┫┫　┃┫┫
 * 　　　┗┻┛　┗┻┛
 */
public class FenLeiDanPinJieAty extends BaseAty implements View.OnClickListener {
    private RecyclerView recyclerViewpinjie;
    private DanPinPinJieAdapter danPinPinJieAdapter;
    public TextView textViewbiaoti;
    private ImageView imageViewback;

    @Override
    protected int setLayout() {
        return R.layout.fenleidanpinjielayout;
    }

    @Override
    protected void initView() {

        recyclerViewpinjie = bindView(R.id.recycleview_pinjie);
        textViewbiaoti = bindView(R.id.text_biaoti);
        imageViewback = bindView(R.id.tiaoxuanliwuback);
        imageViewback.setOnClickListener(this);

    }


    @Override
    protected void initData() {

        Intent intent = getIntent();
        String url = intent.getStringExtra("key");
        String name = intent.getStringExtra("name");
        textViewbiaoti.setText(name);

        NetTool netTool = new NetTool();
        danPinPinJieAdapter = new DanPinPinJieAdapter(getApplicationContext());
        GridLayoutManager manager = new GridLayoutManager(getApplicationContext(), 2);
        danPinPinJieAdapter = new DanPinPinJieAdapter(getApplicationContext());
        recyclerViewpinjie.setLayoutManager(manager);
        recyclerViewpinjie.setAdapter(danPinPinJieAdapter);
        netTool.getNetData(url, DanPinPinJieBean.class, new NetTool.NetListener<DanPinPinJieBean>() {
            @Override
            public void onSuccess(DanPinPinJieBean danPinPinJieBean) {
                danPinPinJieAdapter.setDanPinPinJieBean(danPinPinJieBean);

            }

            @Override
            public void onError(String errorMsg) {

            }
        });


    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tiaoxuanliwuback:
                finish();
                break;

        }
    }
}
